var app = getApp();

Page({
    data: {
        issq: !1,
        showModal: !1,
        kgvip: !1,
        isvip: !1
    },
    tzbj: function() {
        wx.navigateTo({
            url: "myinfo"
        });
    },
    tzewm: function() {
        wx.navigateTo({
            url: "ewm"
        });
    },
    xszz: function() {
        this.setData({
            showModal: !0
        });
    },
    yczz: function() {
        this.setData({
            showModal: !1
        });
    },
    glkq: function() {
        wx.showModal({
            title: "提示",
            content: "此功能正在开发中，敬请期待"
        });
    },
    sjvip: function() {
        this.data.issq ? wx.navigateTo({
            url: "sjvip"
        }) : wx.showModal({
            title: "温馨提示",
            content: "成功开通门店后方能升级VIP"
        });
    },
    tjhxy: function() {
        this.data.issq ? wx.navigateTo({
            url: "tjhxy/tjhxy"
        }) : wx.showModal({
            title: "温馨提示",
            content: "成功开通门店并且发布券后方能添加核销员"
        });
    },
    tzxcx: function(t) {
        console.log(t.currentTarget.dataset.appid), wx.navigateToMiniProgram({
            appId: t.currentTarget.dataset.appid,
            success: function(t) {
                console.log(t);
            }
        });
    },
    previewImage: function(t) {
        console.log(t.currentTarget.dataset.img), wx.previewImage({
            current: t.currentTarget.dataset.img,
            urls: [ t.currentTarget.dataset.img ]
        });
    },
    onLoad: function(t) {
        var a = wx.getStorageSync("xtxx"), e = getApp().imgurl;
        console.log(a), this.setData({
            xtxx: a,
            url: e
        });
    },
    reLoad: function() {
        console.log("reLoad()");
        var t = this;
        app.getUserInfo(function(a) {
            t.setData({
                userInfo: a
            });
        });
    },
    onReady: function() {},
    changeData: function() {
        console.log("changeData");
        var t = wx.getStorageSync("UserData").id;
        console.log(t);
        var a = this;
        app.util.request({
            url: "entry/wxapp/UserInfo",
            cachetime: "0",
            data: {
                user_id: t
            },
            success: function(t) {
                console.log("用户信息", t.data), app.util.request({
                    url: "entry/wxapp/Upgrade",
                    cachetime: "0",
                    data: {
                        level: t.data.grade
                    },
                    success: function(e) {
                        if (console.log("Upgrade", e.data), e.data) {
                            var o = (Number(e.data.threshold) - Number(t.data.level_cumulative)).toFixed(2);
                            console.log(o);
                            var n = (Number(t.data.level_cumulative) / Number(e.data.threshold) * 100).toFixed(2);
                            a.setData({
                                Upgrade: e.data,
                                sjxfje: o,
                                sjjd: n
                            });
                        } else a.setData({
                            Upgrade: "",
                            sjxfje: "",
                            sjjd: 100
                        });
                    }
                }), a.setData({
                    userInfo: t.data
                });
            }
        });
    },
    onShow: function() {
        var t = this;
        wx.getSetting({
            success: function(a) {
                console.log(a), a.authSetting["scope.userInfo"] || t.reLoad();
            }
        }), this.changeData();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.changeData(), setTimeout(function() {
            wx.stopPullDownRefresh();
        }, 1e3);
    },
    onReachBottom: function() {}
});